//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class SCLRecord : WorksheetLevelRecord
    {
        private ushort dscl;
        private ushort nscl;

        public SCLRecord(int zoomScale)
        {
            nscl = (ushort) zoomScale;
            dscl = 100;
        }

        public SCLRecord()
        {
        }

        internal override void Apply(BiffReaderWorksheetContext context)
        {
            context.Worksheet.View.ZoomScale = (int) (nscl/(double) dscl*100);
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.Scl; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.WriteUInt16(nscl);
            context.WriteUInt16(dscl);
        }

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            nscl = context.ReadUInt16();
            dscl = context.ReadUInt16();
        }
    }
}